package cn.wgd.zmx.controller;

import cn.wgd.zmx.domain.Menu;
import cn.wgd.zmx.model.TreeNode;
import cn.wgd.zmx.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
@Api("菜单")
public class MenuController {

    @Autowired
    @ApiModelProperty("注入菜单service层")
    private MenuService menuService;

    @ApiOperation(value = "菜单加载")
    @ApiImplicitParam(name = "role", value = "用户所属角色", required = true, dataType = "String")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public List<TreeNode> getMenuByRole(@RequestParam("role") String role){
        if(StringUtils.isEmpty(role)){
            throw new IllegalArgumentException();
        }
        return menuService.getMenuByRole(role);
    }
}
